<template>
  <el-date-picker
    style="width: 100%"
    @change="handleChange"
    v-model="model"
    :disabled="item.disabled"
    :value-format="item.valueFormat || format"
    :type="item.type"
    :format="item.format || format"
    :placeholder="getPlaceholder('请输入')"
    :clearable="item.clearable || true"
    :range-separator="item.rangeSeparator || '-'"
    :start-placeholder="item.startPlaceholder || '开始时间'"
    :end-placeholder="item.endPlaceholder || '结束时间'"
    :picker-options="item.pickerOptions"
    :editable="item.editable || false"
  >
  </el-date-picker>
</template>

<script>
import yDefault from "./y-default.vue";
export default {
  includesComponent: [
    "date",
    "week",
    "month",
    "year",
    "daterange",
    "datetime",
    "datetimerange",
  ],
  name: "allTimeSelect",
  extends: yDefault,
  computed: {
    format() {
      let type = this.item.type,
        format = null;
      switch (type) {
        case "date":
          format = "yyyy-MM-dd";
          break;

        case "week":
          format = "";
          break;
        case "month":
          format = "yyyy-MM";
          break;
        case "year":
          format = "yyyy";
          break;
        case "daterange":
          format = "yyyy-MM-dd";
          break;
        default:
          format = "yyyy-MM-dd HH:mm:ss";
          break;
      }
      return format;
    },
  },
};
</script>